<template>
  <div class="createPost-container" >
    <el-form ref="postForm" :model="postForm" class="form-container">

      <sticky :z-index="10" :class-name="'sub-navbar '+'pulished'">
        <el-button v-loading="loading" style="margin-left: 10px;float:left;margin-top: 5px;" type="primary"  @click="goBack">
          返回
        </el-button>
        <el-button v-loading="loading" type="success" @click="submitForm">
          确认编辑
        </el-button>
      </sticky>

      <div class="createPost-main-container">
        <el-row>
          <el-col :span="24">

            <el-form-item style="margin-bottom: 40px; margin-left: 35px" prop="groupName">
              <MDinput style="width:500px;" v-model="postForm.groupName" :maxlength="100" name="name" required>
                群 组 名
              </MDinput>
            </el-form-item>

            <div class="postInfo-container">
              <el-row>
                <el-col :span="7">
                  <el-form-item label-width="120px" label="创建者ID:" class="postInfo-container-item">
                    <el-input v-model="postForm.remark1" style="width:200px;"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label-width="120px" label="创建时间:" class="postInfo-container-item">
                    <el-date-picker v-model="postForm.remark3" type="datetime" format="yyyy-MM-dd HH:mm:ss" placeholder="请 输 入" />
                  </el-form-item>
                </el-col>
                <el-col :span="7">
                  <el-form-item label-width="120px" label="群组规模:" class="postInfo-container-item">
                    <el-input v-model="postForm.groupSize" style="width:200px;" placeholder="请 输 入"/>
                  </el-form-item>
                </el-col>
              </el-row>
            </div>

          </el-col>
        </el-row>

        <el-form-item style="margin-bottom: 40px;" label-width="120px" label="群 组 简 介:">
          <el-input v-model="postForm.description" :rows="1" style="width: 670px" type="textarea" class="article-textarea" autosize placeholder="输 入 说 明" />
        </el-form-item>

      </div>
    </el-form>
  </div>
</template>

<script>
  import Tinymce from '@/components/Tinymce'
  import { fetchGroupDetail } from '@/api/group'
  import Sticky from '@/components/Sticky'
  import MDinput from '@/components/MDinput'
  import { parseTime } from '@/utils'
  import { mapGetters } from 'vuex'

  const defaultForm = {
    id:'',
    groupId: '',
    groupName: '',
    groupSize: '',
    remark1: '',
    remark2: '', // 文章外连接
    remark3: undefined,
    displayTime: undefined,
    description: ''
  }

  export default {
    name: 'GroupDetail',
    components:{ fetchGroupDetail, Sticky, MDinput, parseTime,Tinymce },

    props: {
      isEdit: {
        type: Boolean,
        default: true
      }
    },

    data(){
      return{
        loading: false,
        postForm: Object.assign({}, defaultForm),
      }
    },

    computed: {
      ...mapGetters([
        'authName',
        'roles'
      ]),

    },

    created() {
      if (this.isEdit) {
        const id = this.$route.params && this.$route.params.id
        this.getGroupDetail(id)
      }else{
        this.postForm.remark1=this.authName
      }
    },
    methods:{
      getGroupDetail(id){
        fetchGroupDetail(id).then(response => {
          this.postForm = response.data
        }).catch(err => {
          console.log(err)
        })
      },

      submitForm(){
        console.log('666')
      },

      goBack(){
        this.$router.go(-1)
      }
    }
  }
</script>

<style scoped lang="scss">
  .createPost-container {
    position: relative;

    .createPost-main-container {
      padding: 40px 45px 20px 50px;

      .postInfo-container {
        position: relative;
        margin-bottom: 10px;

        .postInfo-container-item {
          float: left;
        }
      }
    }

    .word-counter {
      width: 40px;
      position: absolute;
      right: 10px;
      top: 0px;
    }
  }
</style>
